package com.zz.examine.case3;

import javax.swing.*;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Test {
   public static void main(String args[]){
       //1.找出从起始日子到目标月份的全部日子
       //拿到起始休息日
       LocalDate startDate = LocalDate.of(2022, 2, 3);

       //拿到用户查询的年份和月份，再拿到日子
       Scanner sc = new Scanner(System.in);
       System.out.println("请输入您要查询的年份和月份，以便为你展示休息日（注意：必须是2022-02月开始或之后）");
       String currentDate = sc.next() + "-01";//为了方便解析
//       DateTimeFormatter dft = DateTimeFormatter.ofPattern("yyyy-MM");无法解析
       LocalDate endMonthFistDate = LocalDate.parse(currentDate);
       LocalDate endDate =  endMonthFistDate;
       //拿到这个月份的最后一天日子作为截止日期
       endDate = endDate.plusMonths(1).minusDays(1);
       System.out.println(endDate);

       //起始日子，一直拿到截止日子中的全部日子，方便标记休息日，后面进行信息查询
       List<Day> days = new ArrayList <>();
       while(startDate.isBefore(endDate)){
           Day day = new Day(startDate);
           days.add(day);
           //把这个日子走向下一日
           startDate = startDate.plusDays(1);
       }
       System.out.println("起点开始的全部日子" + days);

       //4.从头开始遍历，标记是否休息
       for(int i = 0; i < days.size(); i += 3){
           Day day = days.get(i);
           day.setFlag(true);//休息
       }
       //5.展示当月的休息日情况
       List<Day> currentDayResst = new ArrayList <>();
       for(int i = 0; i < days.size(); i++){
           Day day = days.get(i);
           if(day.getDate().isBefore(endMonthFistDate)){
               continue;
           }
           day.printInfo();
       }
       System.out.println();
   }

}
